import mongoose from 'mongoose'

let {Schema} = mongoose

const articleSchema = new Schema({
    title : {type : String, required : true}, //标题
    description: { type: String, required: true }, //描述
    url: { type: String, required: true }, //重写的url
    sort: { type: Number, default: 0 }, //排序值
    type: { type: String, required: true }, //类型值
    content: { type: String, required: true }, //文章内容
    date: { type: Date, default: Date.now }, //文章最后更改时间
    hidden: { type: Boolean, default: false}, //文章是否隐藏
    preContent: { type: String, required: true }, //预览文章内容
    preImg: { type: String, required: true } //预览图片url
})

const articleTypeSchema = new Schema({
    value: { type: String, required: true }
})

articleSchema.index({ url: 1 }) //设置url为索引

export const article = mongoose.model('article', articleSchema) //创建文章实例,article为表名

export const type = mongoose.model('article_type', articleTypeSchema) //创建文章类型实例article_type为表名
